package com.scau.phradmin.domain.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.scau.phradmin.domain.entity.MedicineData;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

@Component
public interface MedicineDataMapper extends BaseMapper<MedicineData> {
    /**
     * 查找所有表单（分页）
     * @return
     */
    @Select("select * " +
            "from " +
            "medicine_data " +
            "order by id ")
    public List<MedicineData> queryAll(Page page);

    @Select(" select name" +
            " from medicine_data" +
            " order by name")
    public List<String> listMedicineDataName(Page page);

    /**
     * 统计指定国字标准数目，用于判断是否重复
     */
    @Select("select count(permit_id) from medicine_data where permit_id = #{permitId}")
    public Integer permitIdCount(String permitId);

    /**
     * 查询唯一记录
     * @param id
     * @return
     */
    @Select("select * " +
            "from " +
            "medicine_data " +
            "where id=#{id};")
    MedicineData queryOne(Integer id);

    /**
     * 传入MedicineData的名称，通过名字模糊查询(分页)
     * 注意：只支持前缀的查询
     * @param name
     * @return
     */
    @Select(" SELECT * FROM medicine_data where name like #{medicineName}\"%\" " +
            " union " +
            " SELECT * FROM medicine_data where alias like #{medicineName}\"%\" " +
            " union " +
            " SELECT * FROM medicine_data foreign_name like #{medicineName}\"%\" " +
            " order by name")
    public List<MedicineData> searchByName(@Param(value = "medicineName") String name, Page page);
}
